package com.zhz.system.controller;

import com.zhz.common.tool.mybatisplus.base.core.contract.BaseRequest;
import com.zhz.common.tool.mybatisplus.base.core.contract.R;
import com.zhz.system.biz.PermissionBizService;
import com.zhz.system.contract.request.*;
import com.zhz.system.contract.response.PermissionFindAllResponse;
import com.zhz.system.contract.response.PermissionFindByIdResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 权限控制
 *
 * @author zhouhengzhe
 * @date 2023/3/30
 */
@Api("权限控制")
@RestController
@RequestMapping("/sys/permission")
public class PermissionController {
    @Autowired
    private PermissionBizService permissionBizService;

    @ApiOperation("保存权限")
    @PostMapping("/save")
    public R<Void> save(@RequestBody @Validated(BaseRequest.Save.class) PermissionSaveRequest permissionSaveRequest) throws Exception {
        permissionBizService.save(permissionSaveRequest);
        return R.ok();
    }

    @ApiOperation("修改权限")
    @PostMapping("update")
    public R<Void> update(@RequestBody @Validated(BaseRequest.Update.class) PermissionUpdateRequest permissionUpdateRequest) throws Exception {
        permissionBizService.update(permissionUpdateRequest);
        return R.ok();
    }

    @ApiOperation("查询权限列表")
    @PostMapping("/findAll")
    public R<PermissionFindAllResponse> findAll(@RequestBody PermissionFindAllRequest permissionFindAllRequest) {
        return R.ok(permissionBizService.findAll(permissionFindAllRequest));
    }

    @ApiOperation("根据ID查询权限")
    @PostMapping("findById")
    public R<PermissionFindByIdResponse> findById(@RequestBody PermissionFindByIdRequest permissionFindByIdRequest) {
        return R.ok(permissionBizService.findById(permissionFindByIdRequest));
    }


    @ApiOperation("根据id删除权限")
    @PostMapping("deleteById")
    public R<Void> deleteById(@RequestBody @Validated(BaseRequest.Delete.class)  PermissionDeleteByIdRequest permissionDeleteRequest) {
        permissionBizService.deleteById(permissionDeleteRequest);
        return R.ok();
    }
}
